namespace EFS.Common.Functions
{
	public static class Date
	{
		public static System.String GetDayOfMonthWithSuffix(System.Int32 dayOfMonth)
		{
			// get day suffix
			System.String daySuffix = "th";
			switch (dayOfMonth)
			{
				case 1:
				case 21:
				case 31:
				{
					daySuffix = "st";
					break;
				}
				case 2:
				case 22:
				{
					daySuffix = "nd";
					break;
				}
				case 3:
				case 23:
				{
					daySuffix = "rd";
					break;
				}
				default:
				{
					break;
				}
			}

			// create value
			System.Text.StringBuilder sbDayValue = new System.Text.StringBuilder();
			sbDayValue.AppendFormat("{0}{1}",
				dayOfMonth,
				daySuffix);

			// okj
			return sbDayValue.ToString();
		}

		// get date formated
		public static System.String GetFormated(
			System.IFormatProvider cultureInfo,
			System.DateTime date)
		{
			return date.ToString("d", cultureInfo);
		}

		/// <summary>
		/// Get Age from BOB
		/// </summary>
		public static System.Int32 AgeFromBob(System.DateTime dob)
		{
			// compute 
			System.Int32 age = System.DateTime.Now.Year - dob.Year;

			// comare month
			if (System.DateTime.Now.Month < dob.Month)
			{
				age = age - 1;
			}
			else if (System.DateTime.Now.Month == dob.Month)
			{
				if (System.DateTime.Now.Day < dob.Day)
				{
					age = age - 1;
				}
			}

			// done
			return age;
		}

		/// From string
		public static System.DateTime? From(System.String value)
		{
			// try parse
			return (System.DateTime?)EFS.Common.Formats.FromString(value, typeof(System.DateTime));
		}
	}

}